<?php
namespace Admin\Controller;
use Think\Controller;
use Common\Controller\BaseController;
use Common\ORG\Page;

/**
 * 企业号管理后台
 * 
*/

class QyController extends BaseController {

    //企业号列表
    public function index()
    {
        $res = array('rcode'=>0,'msg'=>'OK');

        $psize = I('get.psize', '','intval');
        $name = I('get.name', '', 'trim'); 

        $MQy = D('Admin/Qy');
        $wheres = array();
        if ($name)
            $wheres['q.qy_name'] = array('like', '%'.$name.'%');
        $wheres['_string'] = '1=1';
        $psize = !$psize||$psize>100 ?  $this->m_psize:$psize;
        $count = $MQy->alias("q")->where( $wheres )->count();
        $Page = new Page( $count, $psize );
        $list = $MQy->alias('q')->field('q.*,pl.name as line_name')
                                ->join("left join product_line pl on pl.product_line_code=q.product_line_code")
                                ->where( $wheres )
                                ->limit( $Page->firstRow.','.$Page->listRows  )
                                ->order("q.qy_code asc")
                                ->select();
        $res['rcode'] = 1;
        $res['data']  = $list;
        $res['page']    =  $Page->getTotalPages();
        $res['p']       = $Page->nowPage;
        $res['psize']   = $psize;
        e_json( $res );
    }

    public function detail()
    {
        $res = array('rcode'=>0,'msg'=>'OK');
        if (IS_GET){
            $qy_code = I('get.code','', 'trim');
            if (!$qy_code){
                $res['msg'] = '参数错误';
            }
            else{
                $MQy = D('Admin/Qy');
                $find = false;
                $wheres = array();
                $wheres['qy_code'] = array('eq', $qy_code);
                $find = $MQy->alias('q')->field('q.*,pl.name as line_name')
                                ->join("left join product_line pl on pl.product_line_code=q.product_line_code")
                                ->where( $wheres )->find();
                if ($find){
                    $res['rcode'] = 1;
                    $res['msg'] = 'OK';
                    $res['data'] = $find;
                }
                else{
                    $res['msg'] = '企业号不存在';
                }
            }
        }
        e_json( $res );
    }
}

?>